home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 5.5 KB | 145 lines | [TEXT/ttxt] |
- --<<<-
- --*******************************************************************************
- --* Demo for: AnalogClock
- --* Required files: reqFiles/rot8shp.sx
- --* anlogclk.sx
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*-----------------------------------------------------------------------------*
- --* Description: This script demonstrates how to create an analog clock.
- --* When you run "anlogclk.sxt", you should see a window
- --* with analog time display.
- --*******************************************************************************
-
- module AnalogClockModule
- uses ScriptX
- end
-
- in module AnalogClockModule
-
- --*=============================================================================*
- --* Set up DirReps
- --*=============================================================================*
- global demoDir := theScriptDir
- global mediaDir := spawn theScriptDir "media"
- global reqFilesDir := spawn theScriptDir "reqfiles"
-
- --*=============================================================================*
- --* Load required files
- --*=============================================================================*
- -- Load Rotating Shape
- fileIn reqFilesDir name:"rot8shp.sx"
-
- -- Load Analog Clock
- fileIn demoDir name:"anlogclk.sx"
-
-
- --*=============================================================================*
- --* Define Demo
- --*=============================================================================*
- class Demo (Window)
- end
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: Demo
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class Demo} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
- colormap:theColormap
- return theBMP
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Demo
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates a 150x150 window.
- --*=============================================================================*
- method init self {class Demo} #rest args ->
- (
- apply nextMethod self boundary:(new Rect x2:150 y2:150) \
- centered:true \
- fill:blackBrush \
- name:"Analog Clock" args
- return self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Demo
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates the analog clock.
- --*=============================================================================*
- method afterInit self {class Demo} #rest args ->
- (
- --*=========================================================================*
- --* Import and create all required bitmaps
- --*=========================================================================*
- local clockFaceBitmap := (importBitmap self mediaDir "clkface.bmp")
- local hourHandBitmap := (importBitmap self mediaDir "hourhand.bmp")
- hourHandBitmap.invisibleColor := whiteColor
- local minHandBitmap := (importBitmap self mediaDir "minhand.bmp")
- minHandBitmap.invisibleColor := whiteColor
-
- --*=========================================================================*
- --* Create an analog clock
- --*=========================================================================*
- local ac := new AnalogClock radius: (ceiling (clockFaceBitmap.bbox.width/2)) \
- clockFace: clockFaceBitmap \
- hourHand: hourHandBitmap \
- minHand: minHandBitmap \
- hourAxis: (new Point x:3 y:37) \
- minAxis: (new Point x:4 y:57)
-
- --*=========================================================================*
- --* Add analog clock to the demo window and display it.
- --*=========================================================================*
- prepend self ac
- show self
-
- return self
- )
-
- --*=============================================================================*
- --* Create a title container
- --*=============================================================================*
- object tc (TitleContainer)
- dir : theScriptDir
- path : "anlogclk.sxt"
- name : "Analog Clock"
- end
-
- --*=============================================================================*
- --* Create demo
- --*=============================================================================*
- object win (Demo)
- title:tc
- end
-
- --*=============================================================================*
- --* Undefine global DirReps
- --*=============================================================================*
- demoDir := undefined
- mediaDir := undefined
- reqFilesDir := undefined
-
- --*=============================================================================*
- --* Store module in the title container
- --*=============================================================================*
- append tc (getModule @AnalogClockModule)
- tc.startUpAction := (tc -> load tc[1]
- startClock win[1]
- show win)
- close tc
- -->>>
-